package com.lagou.controller;

import com.lagou.pojo.User;
import com.lagou.validator.Uservalidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.Errors;
import org.springframework.validation.MapBindingResult;
import org.springframework.validation.ValidationUtils;
import org.springframework.web.bind.annotation.*;

/**
 * @Authther: mrwu
 * @date:2021/3/22-03
 * @Description:com.lagou.controller
 */
@RequestMapping("/user")
@Controller
public class Usercontroller {
    @Autowired
    private Uservalidator uservalidator;

    @ResponseBody
    @GetMapping("/info")
    public String getusers(){
      return "sucess";
    }
    //使用实体bean接受请求参数
    //pojo 接受请求参数
    @ResponseBody//指定json交互
    @GetMapping("/test")
    public String testmodle(User user){

        return user.toString();
    }
    //形参接受参数
    @ResponseBody
    @GetMapping("/name")
    public String testcommen(String name ){
        return "hello"+ name;
    }
    //@pathvariable 接收参数可以接受在URL中的参数
    @ResponseBody
    @GetMapping("/regesiter/{name}")
    public  String testvir(@PathVariable String name){
        return "hello"+ name;
    }
    @ResponseBody
    @GetMapping("/register")
    public String test(@RequestParam String name){
        return "sucess"+name;
    }

   //验证器使用
    @ResponseBody
    @PostMapping("/valida")
    public User validation(@RequestBody User user,Errors errors){
          uservalidator.validate(user,errors);
          System.out.println("123"+errors.toString());
          return user;
    }


}
